<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {include file="/layout/scriptload"}
    <title>添加图文</title>
    <style>
        .form-style{width: 30%;border: solid 1px #d2d6de;padding: 5px 15px;margin-top: 20px;float: left;margin-right: 15px;}
        #box{width: 100%;overflow: hidden;}
    </style>
</head>
<body>
<div class="box">
    <!-- /.box-header -->
    <section class="content">
        <div class="box-body">
            <div>上传成功，填写标题、分类等信息 图片标题若要带表情 请 <a href="http://www.oicqzone.com/tool/emoji/" style="color: #40AFFE;" target="_blank">点击</a> 复制Wechat列表情</div>
            <div id="demo" class="demo"></div>
            <div id="box">
                <!--添加表单-->
            </div>
        </div>

        <input type="hidden" id="fornum" value="0">
        <button id="btn_save" class="btn margin" style="background: #18bc9c;color: #ffffff;display: none;">保存</button>
    </section>
</div>
</body>
<script>
    $(function(){
        $("#box").on('change','.category_sum',function () {
            var $_this = $(this);
            var _id = $_this.val();
            $.ajax({
                type: 'post',
                cache: false,
                url: '{:url("admin/Replyfans/getCategoryChild")}',
                data: {cid: _id},
                success: function (data) {
                    if (data.code == "0") {
                        $_this.parent().next('.form-group').children('.category_child').children('option').remove();
                        $_this.parent().next().next('.form-group').children('.accountpool').children('option').remove();
                        var html = '<option value="">请选择...</option>';
                        $_this.parent().next('.form-group').children(".category_child").append(html);
                        $_this.parent().next().next('.form-group').children(".accountpool").append(html);
                        $.each(data.info, function (index, item) {
                            var html = '<option value="' + item.id + '">' + item.categoryname + '</option>';
                            $_this.parent().next('.form-group').children(".category_child").append(html);
                        });
                    }
                }
            });
        });
        $("#box").on('change','.category_child',function () {
            var $_this2 = $(this);
            var _id = $_this2.val();
            $.ajax({
                type: 'post',
                cache: false,
                url: '{:url("admin/Replyfans/getShieldRule")}',
                data: {cid: _id},
                success: function (data) {
                    if (data.code == "0") {
                        $_this2.parent().next('.form-group').children('.accountpool').children('option').remove();
                        var html = '<option value="">请选择...</option>';
                        $_this2.parent().next('.form-group').children('.accountpool').append(html);
                        $.each(data.info, function (index, item) {
                            var html = '<option value="' + item.id + '">' + item.poolname + '</option>';
                            $_this2.parent().next('.form-group').children('.accountpool').append(html);
                        });
                    }
                }
            });
        });
        $('#btn_save').click(function(){
            var _len = $('#fornum').val();
            for(var i=0;i<=_len;i++){
                var title_ = $("#title_"+i).val();
                var cate_ = $("#cate_"+i).val();
                var child_ = $("#child_"+i).val();
                var pool_ = $("#pool_"+i).val();
                var local_ = $("#local_"+i).val();
                var priority_ = $("#priority_"+i).val();
                var _imgurl =  $("#imgurl_"+i).attr('src');;
                $.ajax({
                    type:'post',
                    cache: false,
                    url:"{:url('replyfans/doAddImgText')}",
                    data:{title:title_,imgurl:_imgurl,category_sum:cate_,category_child:child_,accountpool:pool_,img_local:local_,priority:priority_},
                    success:function(data){

                    }
                })
            }
            layerAlert('保存成功',function () {
                layerParentClose();
                parent.relist();
            });
        })
    })
</script>
</html>